/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TEMP;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.ComponentUI;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Administrator
 */
public class CellRender extends JComboBox implements TableCellRenderer{

    public CellRender() {
        addItem("男");
        addItem("女");
        //this.setUI(new ComponentUI() {});
    }

    public static CellRender getInstance() {
        return CellRenderHolder.INSTANCE;
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        //throw new UnsupportedOperationException("Not supported yet.");
        if(isSelected) {
            setForeground(table.getSelectionForeground());
            super.setBackground(table.getSelectionBackground());
        } else {
            setForeground(table.getForeground());
            super.setBackground(table.getBackground());
        }
        this.setSelectedIndex(value.equals("男") ? 0 : 1);
        return this;
    }

    private static class CellRenderHolder {
        private static final CellRender INSTANCE = new CellRender();
    }
 }
